Repository navigation
fix(android): scope the FileProvider and sanitise picked display names - #303
Conversation
|
@claude review |
|
Claude finished @DeepDiver1975's task in 2m 17s —— View job Review: fix(android): scope the FileProvider and sanitise picked display names
SummaryThe core fix is solid:
Minor: duplicated "lagebuch" literal, no shared constant
var attachmentsDir = System.IO.Path.Combine(AndroidAppPaths.CacheDir(_activity), "lagebuch");The string Nit: silent overwrite on attachment-name collision
Other checked, no issues found
Nothing here blocks merging — the duplicated-literal point is a maintainability suggestion, not a correctness bug in this PR as written. |
The FileProvider previously exposed the entire app cache directory (file_paths.xml's shared_cache pointed at "."), so any granted content:// URI could in principle address import.json, picked attachments, or the synced-attachment cache alongside the files this app actually intends to share or open. It now exposes exactly two subtrees: shared/ (export/share/open targets, via the new AndroidAppPaths.SharedDir) and lagebuch/ (kept for the sibling attachment-open PR, which writes there via Path.GetTempPath() on Android). Picked attachments and the imported master-data JSON move to a new, unexposed AndroidAppPaths.PickedDir instead of landing loose in the cache root. DisplayNameOf also trusted a content provider's DISPLAY_NAME verbatim when building the destination path for a picked attachment, letting a malicious provider write outside the intended directory via a "../"-style name. The new LageBuch.AppLogic.Services.SafeFileName sanitiser (normalise backslashes, take the last path segment, strip platform-invalid characters, fall back to "anhang") closes that off and is unit-tested in isolation since there is no Android test project. Task 4 (fix/review-attachment-names, PR pending) is not yet merged into this branch's base, so AttachmentTempPaths does not exist here yet; OpenFileAsync gating on it is left to a follow-up once that PR lands. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXhXSh2pae9WnaACYUUe3V Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
…efensively Review finding: on this branch's base, FilesViewModel.OpenFileAsync hands Path.Combine(Path.GetTempPath(), row.FileName) to IFileDialogService.OpenFileAsync, which on Android resolves to the bare cache root -- no longer under either file_paths.xml root after the previous commit narrowed exposure. That made FileProvider.GetUriForFile throw IllegalArgumentException (uncaught) for every attachment open until the sibling attachment-open PR (#285) lands and relocates that write into the cache dir's "lagebuch" subtree. AndroidFileDialogService.EnsureShareable is now the sole choke point between a filesystem path and the FileProvider: both ShareFileAsync and OpenFileAsync route through it instead of calling FileProvider.GetUriForFile on a caller-supplied path directly. A path already under SharedDir or under <cache>/lagebuch/ passes through untouched (so the PDF/JSON export paths, which already write straight into SharedDir, incur no second copy); anything else is copied into a fresh SharedDir subfolder first. A non-existent or non-regular-file source is refused (no launch) rather than handed to the provider. This makes the regression structurally impossible regardless of what any caller -- present or future -- passes in. Also: SafeFileName.DefaultFallback is now public so DisplayNameOf can return it directly instead of calling Sanitize(null) just to get the fallback. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXhXSh2pae9WnaACYUUe3V Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
f09a748 to
85eda69
Compare
SafeFileName.Sanitize (#303) and IncidentFile.SanitizeFileName (#285) landed in the same release from two different PRs doing the same job -- reduce an untrusted name to a safe bare file name, fall back to "anhang" -- with rules that had already drifted apart. The AppLogic one stripped only Path.GetInvalidFileNameChars(), which on Linux is NUL and '/' alone. Extract FileNameSanitizer into Domain, the only project both can see, and keep the layer-specific behaviour on top: Create throws, Rehydrate falls back to the storage-style name, SafeFileName substitutes a fallback. The one thing that genuinely differed -- what "nothing usable left" means -- stays with the caller; TrySanitize just reports it as null. This tightens the Android picked-name path, which now also strips the Windows-invalid set, control and format characters, caps at 255 UTF-8 bytes keeping the extension, rejects an all-dots name, and trims. Each of those is a name that previously survived the pick and only broke later, on a peer whose filesystem cared. SafeFileName stays as a name rather than being deleted: the Android head's concern reads as "give me something usable", not "tell me whether this name survives". Part of #302 (the SafeFileName/SanitizeFileName duplication noted in the v0.5.0 merge sequence). Claude-Session: https://claude.ai/code/session_01YavFrkz1GFaMNXbHQKsMyf Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Problem
file_paths.xmlexposed the whole app cache directory through theFileProvider(path="."). That directory also holds the imported master-data JSON, exported PDFs, every picked attachment and the joined-client attachment cache, so any URI handed out by share or open could address any of them.Path.Combine(cacheDir, displayName)with the content provider'sDISPLAY_NAMEused verbatim. A malicious provider can return a name with path separators and write outside the cache directory.Fix
shared/sub-folder (used for share/open and export temp files) and thelagebuch/attachment-open root that the desktop-side fix in fix(files): sanitise attachment names and gate what the OS launcher may open #285 introduced. Picked files and the import JSON live in an unexposedpicked/folder.OpenFileAsyncandShareFileAsyncgo through one choke point: a path already under an exposed root is served as is, anything else is copied into a freshshared/<guid>/folder first, and a non-existent or non-regular file is refused. This holds regardless of the merge order with fix(files): sanitise attachment names and gate what the OS launcher may open #285 and protects future callers that forget the convention.Found during a security review of
main; part of a series of review follow-up PRs.🤖 Generated with Claude Code
https://claude.ai/code/session_01PXhXSh2pae9WnaACYUUe3V